from rest_framework.views import APIView
from ext.error import Throttled

class JKAPIView(APIView):
    def check_permissions(self, request):
        permission_error = []
        for permission in self.get_permissions():
            if permission.has_permission(request, self):
                return permission
            else:
                permission_error.append(permission)
        else:
            self.permission_denied(
                request,
                message=getattr(permission_error[0], 'message', None),
                code=getattr(permission_error[0], 'code', None))
    def throttled(self, request, wait):
        """
        If request is throttled, determine what kind of exception to raise.
        """
        raise Throttled(wait)

